<?php
/**
 * planning/edit-planning.phtml
 */
?>
<?php

use RHX\Helper\RHDateTime;
use RHX\Model\Object\Day;
?>

<?php
// variables
$adapter	 = $this->adapter;
$plannings	 = $this->plannings;
$entrants	 = $this->entrants;
$sortants	 = $this->sortants;
$codes		 = $this->codes;
$codec		 = $this->codec;
$colors		 = $this->colors;
$days		 = $this->days;
$semaine	 = $this->semaine;
$site		 = $this->site;
$dayNames	 = $this->dayNames;
$editable	 = $this->editable;

$dayName	 = array(
    'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche',
);
// temps
$dayOfWeek	 = array(
    'lundi'		 => new RHDateTime(), 'mardi'		 => new RHDateTime(), 'mercredi'	 => new RHDateTime(), 'jeudi'		 => new RHDateTime(), 'vendredi'	 => new RHDateTime(), 'samedi'	 => new RHDateTime(), 'dimanche'	 => new RHDateTime(),
);
$lundi		 = new RHDateTime($this->lundi);
$mardi		 = new RHDateTime($this->lundi);
$mardi->modify('next day');
$mercredi	 = new RHDateTime($this->lundi);
$mercredi->modify('next wednesday');
$jeudi		 = new RHDateTime($this->lundi);
$jeudi->modify('next thursday');
$vendredi	 = new RHDateTime($this->lundi);
$vendredi->modify('next friday');
$samedi		 = new RHDateTime($this->lundi);
$samedi->modify('next saturday');
$dimanche	 = new RHDateTime($this->lundi);
$dimanche->modify('next sunday');

/**
 * Affichage des Pauses
 *
 * @param string|int $value
 * @return string
 */
function showPause($value) {
    if ((int) $value == 1) {
	return 'X';
    }
    else {
	return '';
    }
}

/**
 * Affichage des Repas
 *
 * @param string|int $value
 * @return string
 */
function showRepas($value) {
    if ((int) $value == 1) {
	return '1';
    }
    else {
	return '';
    }
}
?>

<div class="content-body">
    <div class="rhx-goback">
	<button class="btn btn-inverse" onclick="normalScreenLayout();">Retour à la liste des Semaines</button>
    </div>

    <div class='rhx-siteTitle btn'  onclick='$("#" + ID).click();
		return false;'>
		    <?php echo $site->libelle; ?>
    </div>

    <div class="rhx-planning-title">
	<a href="#" id="selectorSemaine" data-type="select" style="color: #fff;" onclick="return false;">
	    <em>Planning <?php echo $semaine->libelle; ?> <b><?php echo $lundi->dateFr(); ?></b> au <b><?php echo $dimanche->dateFr(); ?></b></em>
	</a>
    </div>

    <div id="planning-tabs">
	<!-- LISTE DES TABULTATIONS -->
	<ul>
	    <li>
		<a href="#planning-semaine">Planning Semaine</a>
	    </li>
	    <li>
		<a href="#planning-type">Planning Type</a>
	    </li>
	</ul>

	<!-- PLANNING SEMAINE -->
	<div id="planning-semaine" class="small-font">
	    <!-- Tableau des plannings -->
	    <table class="pl-table" style="font-size: 0.9em;">
		<thead>
		    <tr>
			<td rowspan='2'>Mat.</td>
			<td rowspan='2'>Poste</td>
			<td rowspan='2'>Prénom</td>
			<td rowspan="2">Contrat Horaire</td>
			<?php if ($days['lundi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $lundi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['mardi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $mardi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['mercredi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $mercredi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['jeudi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $jeudi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['vendredi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $vendredi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['samedi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $samedi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['dimanche']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $dimanche->dateFr(); ?></b></td><?php endif; ?>
			<td rowspan="2">Heures modulées</td>
			<td rowspan="2">Ret., Abs. et Dép. Ant.</td>
			<td rowspan="2">Heures non planifiées</td>
		    </tr>
		    <tr>
			<?php foreach ($dayNames as $day): ?>
			    <?php if ($days[$day]): ?>
				<td style="border-left-width: 2px;">Code</td>
				<td>Entrée</td>
				<td>Sortie</td>
				<td>P</td>
				<td>R</td>
				<td style="border-right-width: 2px;">Transfert</td>
			    <?php endif; ?>
			<?php endforeach; ?>
		    </tr>
		</thead>
		<tbody>
		    <?php $jaune = 1; ?>
		    <?php foreach ($plannings as $planning): ?>
			<?php
			// Couleur Jaune
			$colorJaune	 = ($jaune % 2) ? 'jaune1' : 'jaune2';
			$jaune++;
			// Employé
			$employe	 = $planning->getEmploye();
			// Poste
			$poste		 = $employe->getPoste();
			?>
		    <tr>
    			<!-- Informations -->
    			<td class="<?php echo $colorJaune; ?>"><?php echo $employe->getMatricule(true); ?></td>
    			<td class="<?php echo $colorJaune; ?>"><?php echo $poste->code; ?></td>
    			<td class="<?php echo $colorJaune; ?>"><?php echo $employe->prenom; ?>></td>
    			<td class="<?php echo $colorJaune; ?>"><?php echo $employe->getHoraireHebdo(true); ?></td>

			<!-- Jour de la semaine -->
			    <?php foreach ($dayOfWeek as $day): ?>
				<?php
				$planningDay	 = new Day($adapter, $planning, $day);
				$prda		 = $planningDay->whichIsLate();
				$color		 = $color[$planningDay->code];
				$code		 = $planningDay->getCode();
				?>
				<?php if ($days[$day]): ?>
	    			<td id="pl-<?php ?>-<?php echo $day; ?>-code" class="<?php echo $color ?>" style='border-left-width: 2px;'>
	    			    <a href="#" class="edit-link" data-prefix="<?php echo $day; ?>" data-id="<?php echo $planning->id; ?>"><?php echo is_null($code) ? '' : $code->code; ?></a>
	    			</td>
	    			<td id="pl-<?php ?>-<?php echo $day; ?>-entree" class="<?php echo ($prda['retard']) ? 'RT' : $color; ?>">
	    			    <a href="#" class="edit-link" data-prefix="<?php echo $day; ?>" data-id="<?php echo $planning->id; ?>"><?php echo $planningDay->showEntree(); ?></a>
	    			</td>
	    			<td id="pl-<?php ?>-<?php echo $day; ?>-sortie" class="<?php echo ($prda['anticipe']) ? 'DA' : $color; ?>">
	    			    <a href="#" class="edit-link" data-prefix="<?php echo $day; ?>" data-id="<?php echo $planning->id; ?>"><?php echo $planningDay->showSortie(); ?></a>
	    			</td>
	    			<td id="pl-<?php ?>-<?php echo $day; ?>-pause" class="<?php echo $color ?>">
	    			    <a href="#" class="edit-link" data-prefix="<?php echo $day; ?>" data-id="<?php echo $planning->id; ?>"><?php echo $planningDay->showPause(); ?></a>
	    			</td>
	    			<td id="pl-<?php ?>-<?php echo $day; ?>-repas" class="<?php echo $color ?>">
	    			    <a href="#" class="edit-link" data-prefix="<?php echo $day; ?>" data-id="<?php echo $planning->id; ?>"><?php echo $planningDay->showRepas(); ?></a>
	    			</td>
	    			<td style='border-right-width: 2px;' class="stripes"></td>
				<?php endif; ?>
			    <?php endforeach; ?>

				<!-- Heure modulées -->
    				<td></td>
    				<!-- PRDA -->
    				<td>
    				    <span id="pl-<?php echo $planning->id ?>-retard">
					    <?php
					    $heureRetard = RHDateTime::hourNoSecond($planning->retard_heure);
					    echo "$heureRetard({$planning->retard})";
					    ?>
    				    </span>
    				</td>
    				<!-- Heures non plannifié -->
    				<td class="plusValue">
    				    <span id="pl-<?php echo $planning->id ?>-planifie">00:00</span>
    				</td>
    		    </tr>
		    <?php endforeach; ?>
		    <!-- TRANSFERTS -->
		    <?php
		    $colCount = 0;
		    for ($i = 0; $i < 7; $i++) {
			if ($days[$i]) {
			    $colCount+= 6;
			}
		    }
		    $colspan = 4 + $colCount + 3;
		    ?>
		    <tr>
			<td colspan="<?php echo $colspan; ?>" class='jaune3'>
			    Transfert Entrants <a href="#transfert" class="makeTransfert" data-site="<?php echo $site->id; ?>"><img title="Effectuer un Transfert Entrant" src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/transfer-32x32.png" ></a>
			</td>
		    </tr>
		    <!-- Transfert entrants -->
		    <?php
		    foreach ($entrants as $entrant) {
			foreach ($dayNames as $day) {
			    //
			}
		    }
		    ?>
		</tbody>
	    </table>
	</div>

	<!-- PLANNING TYPE -->
	<div id="planning-type">
	    <!-- -->
	</div>
    </div>
</div>

<style type="text/css">
    .rhx-goback{
	position: absolute;
	top: 55px;
	right: 100px;
	z-index: 99;
    }
    .rhx-siteTitle{
	position: absolute;
	top: 55px;
	left: 512px;
	z-index: 99;
	margin: auto;
	padding: 5px 15px;
	background: #7c98b3;
	border-radius: 3px;
	border: solid 1px #faf9f9;
	color: #faf9f9;
	font-size: 1.5em;
	opacity: 0.5;
    }
    .rhx-siteTitle:hover{
	opacity: 1.0;
    }
    .rhx-planning-title{
	position: absolute;
	top: 11px;
	right: 180px;
	color: white;
	font-size: 1.4em;
    }
    .rhPopover{
	position: absolute;
	z-index: 99;
	width: 500px;
    }
    .minusValue, .plusValue{
	display: inline-block;
	width: 100%;
	height: 100%;
	text-align: center;
	color: #ffffff;
    }
    .minusValue{
	background: #ff6633;
    }
    .plusValue{
	background: #008e37;
    }
<?php if (!$editable): ?>
            .edit-link{
    	cursor: not-allowed;
            }
<?php endif; ?>
    #heurePresence{
	font-weight: bolder;
	color: #6600ff;
    }
    .makeTransfert{
	position: relative;
	margin-left: 10px;
	display: inline-block;
	width: 32px;
	height: 32px;
	background: #fff;
	border-radius: 3px;
	box-shadow: 0px 0px 2px 3px #ffb400;
    }
    .icon-transfert{
	position: absolute;
	top: 1px;
	right: 1px;
    }
    .relative-position{
	position: relative;
    }
</style>